package com.neuedu.corejava.ch5.game;


//类指的是类型，是由多个具有相同特征的实物（对象），抽象出来的
public class GameRole {
	//名字
	private String name;
	

	//武器
	private String weapon;
	
	//战斗力
	private int  attack;
	
	//耐力
	private int  endurance;

	
	
	public static void main(String[] args) {
		GameRole sun=new GameRole("孙悟空","金箍棒",5,5);
		sun.fighting();
		sun.defence();
		GameRole tang=new GameRole("唐僧","无",0,5);
		tang.fighting();
		tang.defence();
		GameRole zhu=new GameRole("猪八戒","耙子",4,2);
		zhu.fighting();
		zhu.defence();
		GameRole sha=new GameRole("沙僧","月光铲",3,4);
		sha.fighting();
		sha.defence();
		
		GameRole rGameRole=null;
		for(int i=0;i<10000;i++){
			//在循环外部，超出生命周期的对象都是垃圾，可以进行回收
			GameRole gameRole=new GameRole();
			
			rGameRole=new GameRole();
		}
		System.gc();//通知垃圾回收器回收垃圾，jvm收到通知后，会调度gc进行内存回收
		//内存泄露：当有一个堆内存一直有栈指针执行它，这块堆内存则无法进行回收，这种情况称为内存泄露
		
	}
	
	
	//一个类编写了带参构造方法后，会屏蔽默认的空参构造方法
	//如果需要使用空参构造方法，必须显示编写一个
	public GameRole() {
		super();
		// TODO Auto-generated constructor stub
	}
	
	

	public GameRole(String name, String weapon, int attack, int endurance) {
		super();
		this.name = name;
		this.weapon = weapon;
		this.attack = attack;
		this.endurance = endurance;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getWeapon() {
		return weapon;
	}

	public void setWeapon(String weapon) {
		this.weapon = weapon;
	}

	public int getAttack() {
		return attack;
	}

	public void setAttack(int attack) {
		this.attack = attack;
	}

	public int getEndurance() {
		return endurance;
	}

	public void setEndurance(int endurance) {
		this.endurance = endurance;
	}
	
	//战斗
	public void fighting(){
		System.out.println(name+"在战斗");
	}
	
	//防御
		public void defence(){
			System.out.println(name+"防御");
		}
		
	
	
	
	
	
	
	
	
	
	
	
	

}
